<template>
	<view class="container">
		<view class="title">
			奶茶外卖系统
		</view>
		<input type="text" v-model="userInfo.username" placeholder="请输入用户名称">
		<input type="password" v-model="userInfo.password" placeholder="请输入密码">
		<button class="btn" @click="register">立即注册</button>
		<button class="btn" @click="toLoginPage">肥去登录咯~</button>
		<button class="btn" @click="toBack">返回</button>

	</view>
</template>

<script>
	import {
		register
	} from "@/api/index";

	export default {
		data() {
			return {
				userInfo: {
					username: "",
					password: ""
				}

			}
		},
		methods: {
			toLoginPage() {
				uni.navigateTo({
					url: "/pages/login/login"
				})
			},
			register() {


				register(this.userInfo).then(res => {
					uni.showToast({
						title: res.msg,
						duration: 2000,
					});

					//登录成功需要做的操作 存储数据（本地存储） 跳转页面
					//setTimeout 只执行一次 2秒后进行跳转
					setTimeout(() => {
						uni.navigateTo({
							url: "/pages/login/login"
						})
					}, 2000)

				})



			},
			toBack() {
				uni.navigateBack()
			}
		}
	}
</script>

<style scoped>
	uni-input {
		height: 45px;
		width: 80%;
		font-weight: bold;
		border-radius: 10px;
		padding: 3px 10px;
		margin: 0 auto;
		border: 1px solid #cccc;
		box-sizing: border-box;
		margin-top: 30px;
	}

	button {
		width: 80%;
		font-weight: bold;
		border-radius: 10px;
	}

	.btn {
		background: #fe8787;
		color: #fff;
		margin-top: 30px;
	}


	.title {
		font-size: 25px;
		text-align: center;
		margin-top: 25px;
		font-weight: bold;
		color: pink;
	}
</style>